package cn.kent.controller;

import cn.kent.service.ProductServiceImpl;
import cn.kent.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class ProductController {
    @Autowired
    private ProductServiceImpl productService;

    @RequestMapping("getAll")
    public List<Product> getAll(){
        return productService.list();
    }

    // 创建映射后 添加索引
    @RequestMapping("insertIndex")
    public String insertIndex(){
        try {
            return productService.insertIndex();
        } catch (IOException e) {
            e.printStackTrace();
            return "fail";
        }
    }

    @RequestMapping("search")
    public List<Product> search(@RequestParam("p") String p) throws IOException {
        return productService.search(p);
    }
}
